require "Common/define"
require "Logic/Config"
require "Common/functions"

RedDotsHeroInteractionRewardHandler ={};
local this = RedDotsHeroInteractionRewardHandler;

function RedDotsHeroInteractionRewardHandler.init()
    CloseEvent(Config.EventType.Fresh_Active,this.update);
    ListenEvent(Config.EventType.Fresh_Active,this.update);
    CloseEvent(Config.EventType.Fresh_HeroInteraction,this.update);
    ListenEvent(Config.EventType.Fresh_HeroInteraction,this.update);
    return this;
end

--参数1：指定英雄Id，nil代表检查所有英雄
---英雄详情突破页签红点
function RedDotsHeroInteractionRewardHandler.getFlag(partnerId)
    local flag = Config.RedDotsFlagState.None;
    local heroData=logicMgr.HeroManager.getHeroDatabyPartnerId(partnerId,true)
    if table.isNullOrEmpty(heroData)then
        return Config.RedDotsFlagState.None
    end
    local heroId=heroData.partnerModelId
    local rewardData=logicMgr.HeroFavorManager.getRewardData(heroId)
    if heroData and heroData.favorRewardGetLv then
        for i=heroData.favorRewardGetLv+1,heroData.favorLv do
            if rewardData[i].f_RewardType==3 then
                return Config.RedDotsFlagState.Needful
            end
        end
    end
    
    return flag;
end

function RedDotsHeroInteractionRewardHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.HeroInteractionReward);
end